package com.cddx.logistics.controller;

import com.cddx.logistics.domain.vo.CableStatisticsVo;
import com.cddx.logistics.service.CableStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/statistics/cable")
public class CableStatisticsController {

    @Autowired
    private CableStatisticsService cableStatisticsService;

    @GetMapping("/monthly")
    public List<CableStatisticsVo> getMonthlyStatistics(
            @RequestParam(value = "startDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,

            @RequestParam(value = "endDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,

            @RequestParam(value = "name", required = false)  // 改为按名称查询
            String name) {

        return cableStatisticsService.getCableStatisticsByCondition(
                startDate, endDate, name
        );
    }

    // 新增接口：获取所有物料名称
    @GetMapping("/names")
    public List<String> getAllMaterialNames() {
        return cableStatisticsService.getAllMaterialNames();
    }
}
